package com.rmxx.fruit.activity;

import android.graphics.Color;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.company.android.fruit.R;
import com.kwan.xframe.mvp.presenter.BasePresenter;
import com.kwan.xframe.mvp.view.activity.BaseCommonRecycleActivity;
import com.rmxx.fruit.bean.Product;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ProductListActivity extends BaseCommonRecycleActivity {

	List<Product> mProduct = new ArrayList<>();

	View v_line_all, v_line_sell, v_line_new, v_line_price,
			ll_all, ll_sell, ll_new, ll_price;
	TextView tv_all, tv_sell, tv_new, tv_price;

	@Override
	protected RecyclerView.ItemDecoration getItemDecoration() {
		return null;
	}

	BaseQuickAdapter<Product, BaseViewHolder> mAdapter;
	@Override
	protected BaseQuickAdapter getAdapter() {

		Product product = new Product();
		product.setRicon(R.mipmap.product2_01);
		product.setName("澳洲牛腱子1kg进口牛肉");
		product.setDesc("无污染基地牧草饲养来自于大自然的…");
		product.setPrice(89.00f);
		mProduct.add(product);

		product = new Product();
		product.setRicon(R.mipmap.product2_02);
		product.setName("佳沛金奇异果");
		product.setDesc("在乎生活中的每件小事");
		product.setPrice(148.00f);
		mProduct.add(product);

		product = new Product();
		product.setRicon(R.mipmap.product2_03);
		product.setName("新鲜小土豆10斤农家自种蔬菜");
		product.setDesc("在乎生活中的每件小事");
		product.setPrice(19.88f);
		mProduct.add(product);

		product = new Product();
		product.setRicon(R.mipmap.product2_04);
		product.setName("麻辣小龙虾香辣味鲜活现做");
		product.setDesc("个大体肥 鲜美入味 肉质Q谈");
		product.setPrice(69.88f);
		mProduct.add(product);

		mAdapter =
				new BaseQuickAdapter<Product, BaseViewHolder>(R.layout.list_item_shop_product, mProduct) {
					@Override
					protected void convert(BaseViewHolder helper, Product item) {
						helper.setImageResource(R.id.iv_icon, item.getRicon());
						helper.setText(R.id.tv_name, item.getName());
						helper.setText(R.id.tv_price, "¥" + item.getPrice());
						helper.setText(R.id.tv_desc, item.getDesc());
					}
				};
		mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
			@Override
			public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
				go2Activity(ProductActivity.class,null,false);
			}
		});
		return mAdapter;
	}

	@Override
	protected RecyclerView.LayoutManager getLayoutManager() {
		return new LinearLayoutManager(this);
	}


	@Override
	protected void initViews() {
		super.initViews();

		v_line_all = findViewById(R.id.v_line_all);
		v_line_sell = findViewById(R.id.v_line_sell);
		v_line_new = findViewById(R.id.v_line_new);
		v_line_price = findViewById(R.id.v_line_price);
		ll_all = findViewById(R.id.ll_all);
		ll_sell = findViewById(R.id.ll_sell);
		ll_new = findViewById(R.id.ll_new);
		ll_price = findViewById(R.id.ll_price);
		tv_all = findViewById(R.id.tv_all);
		tv_sell = findViewById(R.id.tv_sell);
		tv_new = findViewById(R.id.tv_new);
		tv_price = findViewById(R.id.tv_price);

	}

	@Override
	protected void initViewSetting() {
		super.initViewSetting();
		ll_all.setOnClickListener(this);
		ll_sell.setOnClickListener(this);
		ll_new.setOnClickListener(this);
		ll_price.setOnClickListener(this);

		refreshLayout.setEnableRefresh(false);
		refreshLayout.setEnableLoadMore(false);
	}

	@Override
	protected void initData() {

	}

	@Override
	protected BasePresenter getBasePresenter() {
		return null;
	}

	@Override
	protected String getTitleTxt() {
		return null;
	}

	@Override
	public String getPageName() {
		return null;
	}


	@Override
	protected int getTopViewId() {
		return R.layout.activity_product_list_title;
	}

	@Override
	public void onClick(View v) {
		super.onClick(v);

		if (v == ll_all) {

			tv_all.setTextColor(getResources().getColor(R.color.mainRed));
			tv_sell.setTextColor(Color.parseColor("#999999"));
			tv_new.setTextColor(Color.parseColor("#999999"));
			tv_price.setTextColor(Color.parseColor("#999999"));
			v_line_all.setVisibility(View.VISIBLE);
			v_line_sell.setVisibility(View.INVISIBLE);
			v_line_new.setVisibility(View.INVISIBLE);
			v_line_price.setVisibility(View.INVISIBLE);

			Collections.shuffle(mProduct);
			mAdapter.setNewData(mProduct);

		} else if (v == ll_sell) {
			tv_sell.setTextColor(getResources().getColor(R.color.mainRed));
			tv_all.setTextColor(Color.parseColor("#999999"));
			tv_new.setTextColor(Color.parseColor("#999999"));
			tv_price.setTextColor(Color.parseColor("#999999"));
			v_line_all.setVisibility(View.INVISIBLE);
			v_line_sell.setVisibility(View.VISIBLE);
			v_line_new.setVisibility(View.INVISIBLE);
			v_line_price.setVisibility(View.INVISIBLE);
			Collections.shuffle(mProduct);
			mAdapter.setNewData(mProduct);
		} else if (v == ll_new) {
			tv_new.setTextColor(getResources().getColor(R.color.mainRed));
			tv_sell.setTextColor(Color.parseColor("#999999"));
			tv_all.setTextColor(Color.parseColor("#999999"));
			tv_price.setTextColor(Color.parseColor("#999999"));
			v_line_all.setVisibility(View.INVISIBLE);
			v_line_sell.setVisibility(View.INVISIBLE);
			v_line_new.setVisibility(View.VISIBLE);
			v_line_price.setVisibility(View.INVISIBLE);
			Collections.shuffle(mProduct);
			mAdapter.setNewData(mProduct);
		} else if (v == ll_price) {
			tv_price.setTextColor(getResources().getColor(R.color.mainRed));
			tv_sell.setTextColor(Color.parseColor("#999999"));
			tv_new.setTextColor(Color.parseColor("#999999"));
			tv_all.setTextColor(Color.parseColor("#999999"));
			v_line_all.setVisibility(View.INVISIBLE);
			v_line_sell.setVisibility(View.INVISIBLE);
			v_line_new.setVisibility(View.INVISIBLE);
			v_line_price.setVisibility(View.VISIBLE);
			Collections.shuffle(mProduct);
			mAdapter.setNewData(mProduct);
		}
	}
}
